package com.baoxin.chenxixc4coach;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.baoxin.chenxixc4coach.utils.ImageSaveUtils;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class MyPosterActivity extends BaseActivity {

    private ImageView mPoster;

    public static void startAciton(Context context, String url) {
        Intent intent = new Intent(context, MyPosterActivity.class);
        intent.putExtra("imgUrl", url);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_poster);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);//去掉默认title
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mPoster = findViewById(R.id.my_poster);

        GlideApp.with(this)
                .load(getIntent().getStringExtra("imgUrl"))
                .into(mPoster);

    }

    /**
     * 保存到本地
     *
     * @param view
     */
    public void onSave(View view) {

        mPoster.setDrawingCacheEnabled(true);
        boolean success = ImageSaveUtils.saveImageToGallery(this, mPoster.getDrawingCache());
        mPoster.setDrawingCacheEnabled(false);
        if (success) {
            Toast.makeText(activity, "保存成功！", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(activity, "保存失败！", Toast.LENGTH_SHORT).show();
        }
    }


}
